Public Class M_Tenant_ID
    Dim dtable As New DataTable
    Dim dadapter As New OleDb.OleDbDataAdapter
    Private t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12 As String
    Dim nw As Boolean
    Private Sub load_grid()
        dtable.Clear()
        open_con()
        dadapter = New OleDb.OleDbDataAdapter("select * from vw_tenant_id", DbCon)
        dadapter.Fill(dtable)
        DataGridView1.DataSource = dtable
        DataGridView1.Columns(0).Visible = False
        DataGridView1.Columns(1).Visible = False
        DataGridView1.Columns(2).Visible = False
        DataGridView1.Columns(3).Visible = False
        DataGridView1.Columns(4).Visible = False
        DataGridView1.Columns(5).Visible = False
        'DataGridView1.Columns(4).HeaderText = "Level"
        DataGridView1.RowHeadersVisible = False
        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DataGridView1.AutoResizeColumns()
        DataGridView1.ReadOnly = True
        DbCon.Close()
    End Sub
    Private Sub detail(ByVal id)
        open_db("select * from vw_tenant_id where id=" & id)
        While Read.Read()
            TextBox1.Text = isnull(Read("tenant_id"))
            TextBox2.Text = isnull(Read("orang1"))
            TextBox3.Text = isnull(Read("orang2"))
            TextBox4.Text = isnull(Read("orang3"))
            TextBox5.Text = isnull(Read("orang4"))
            TextBox6.Text = isnull(Read("orang5"))
            TextBox7.Text = isnull(Read("id"))
            TextBox8.Text = isnull(Read("tenant1"))
            TextBox9.Text = isnull(Read("tenant2"))
            TextBox10.Text = isnull(Read("tenant3"))
            TextBox11.Text = isnull(Read("tenant4"))
            TextBox12.Text = isnull(Read("tenant5"))
        End While
        close_db()
        set_param(id)
    End Sub
    Private Sub set_param(ByVal id)
        t0 = id
        t1 = TextBox1.Text
        t2 = TextBox2.Text
        t3 = TextBox3.Text
        t4 = TextBox4.Text
        t5 = TextBox5.Text
        t6 = TextBox6.Text
        t7 = TextBox7.Text
        t8 = TextBox8.Text
        t9 = TextBox9.Text
        t10 = TextBox10.Text
        t11 = TextBox11.Text
        t12 = TextBox12.Text
    End Sub

    Private Sub M_Tenant_ID_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        load_grid()
        nw = True
        set_param("")
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        detail(DataGridView1.Item(0, DataGridView1.CurrentRow.Index).Value)
        nw = False
    End Sub
    Private Sub DataGridView1_Keyup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
        If e.KeyCode = Keys.Down Then
            If DataGridView1.CurrentRow.Index + 1 < DataGridView1.RowCount Then
                detail(DataGridView1.Item(0, DataGridView1.CurrentRow.Index + 1).Value)
            End If
        End If
        If e.KeyCode = Keys.Up Then
            If DataGridView1.CurrentRow.Index - 1 >= 0 Then
                detail(DataGridView1.Item(0, DataGridView1.CurrentRow.Index - 1).Value)
            End If
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm2 As New M_Tenant
        'If TextBox8.Text = "" Then
        TextBox2.Text = frm2.getselection(TextBox8.Text)
        TextBox8.Text = T_id
        'Else
        'TextBox2.Text = frm2.getselection("select * from m_tenant where tenant_id=" & TextBox8.Text)
        'TextBox8.Text = T_id
        'End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim frm2 As New M_Tenant
        'If TextBox9.Text = "" Then
        TextBox3.Text = frm2.getselection(TextBox9.Text)
        TextBox9.Text = T_id
        'Else
        'TextBox3.Text = frm2.getselection("select * from m_tenant where tenant_id=" & TextBox8.Text)
        'TextBox9.Text = T_id
        'End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim frm2 As New M_Tenant
        'If TextBox10.Text = "" Then
        TextBox4.Text = frm2.getselection(TextBox10.Text)
        TextBox10.Text = T_id
        'Else
        'TextBox4.Text = frm2.getselection("select * from m_tenant where tenant_id=" & TextBox8.Text)
        'TextBox10.Text = T_id
        'End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim frm2 As New M_Tenant
        'If TextBox11.Text = "" Then
        TextBox5.Text = frm2.getselection(TextBox11.Text)
        TextBox11.Text = T_id
        'Else
        'TextBox5.Text = frm2.getselection("select * from m_tenant where tenant_id=" & TextBox8.Text)
        'TextBox11.Text = T_id
        'End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim frm2 As New M_Tenant
        'If TextBox12.Text = "" Then
        TextBox12.Text = frm2.getselection(TextBox12.Text)
        TextBox6.Text = T_id
        'Else
        'TextBox6.Text = frm2.getselection("select * from m_tenant where tenant_id=" & TextBox8.Text)
        'TextBox12.Text = T_id
        'End If
    End Sub
End Class